package com.teamwork.ZuccEcho.Repository;

import com.teamwork.ZuccEcho.Entity.Answersheet;
import com.teamwork.ZuccEcho.Entity.Qnquestion;
import com.teamwork.ZuccEcho.Entity.Questionnaire;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;

import javax.transaction.Transactional;
import java.util.Date;
import java.util.List;

public interface StudentFeedBackApiRepository extends JpaRepository<Answersheet,Long>, JpaSpecificationExecutor<Answersheet> {
    Answersheet findById(long id);

    @Transactional
    @Modifying
    @Query(value = "insert into answersheet(qn_id,stu_id,as_submittime,as_status) values(?1,?2,?3,'待提交')",nativeQuery = true)
    void addAnswersheet(long qn_id, String stu_id, Date as_submittime);

    @Query(value = "select max(as_id) from answersheet",nativeQuery = true)
    int findAnswersheetId();

    @Transactional
    @Modifying
    @Query(value = "insert into answer(as_id,a_qtypes,a_content) values(?1,?2,?3)",nativeQuery = true)
    void addAnswer(long as_id,int a_qtypes,String a_content);

    @Query(value = "select * from answersheet where qn_id=?1 && stu_id=?2",nativeQuery = true)
    Answersheet findAnswersheet(long qn_id,String stu_id);

    @Query(value = "select * from answersheet where stu_id=?1",nativeQuery = true)
    List<Answersheet> findAnswersheets(String stu_id);
}
